﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace MsTestUtilities.SolutionAnalysis.Testing
{
    public class ProjectAssert : CollectionAssertionBase<CsProject>
    {
        public ProjectAssert(IEnumerable<CsProject> projects)
            : base(projects)
        {
        }

        public BuildConfigurationAssert ForConfigurations(string configurationName)
        {
            return ForAllConfigurations(c => 
                c.Configuration.Equals(configurationName, StringComparison.InvariantCultureIgnoreCase));
        }

        public BuildConfigurationAssert ForConfigurations(string configurationName, string platform)
        {
            return ForAllConfigurations(c => 
                c.Configuration.Equals(configurationName, StringComparison.InvariantCultureIgnoreCase)
                && c.Platform.Equals(platform, StringComparison.InvariantCultureIgnoreCase));
        }

        public BuildConfigurationAssert ForAllConfigurations()
        {
            return new BuildConfigurationAssert(Elements.SelectMany(p => p.BuildConfigurations));
        }        

        public BuildConfigurationAssert ForAllConfigurations(Predicate<BuildConfiguration> predicate)
        {
            return new BuildConfigurationAssert(Elements.SelectMany(p => p.BuildConfigurations.Where(c => predicate(c))));
        }
        
        public ContentFileAssert ForAllContentFiles()
        {
            return new ContentFileAssert(Elements.SelectMany(p => p.ContentFiles));
        }

        protected override string ElementName(CsProject project)
        {
            return project.Name;
        }

        public ReferenceAssert ForAllReferences()
        {
            return new ReferenceAssert(Elements.SelectMany(p => p.References));
        }

        public ProjectReferenceAssert ForAllProjectReferences()
        {
            return new ProjectReferenceAssert(Elements.SelectMany(p => p.ProjectReferences));
        }
    }
}
